home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 196_01 / fp_math.doc < prev    next >
INI File  |  1985-11-13  |  4KB  |  97 lines

  1. [FP-MATH.DOC of JUGPDS Vol.19]
  2.  
  3.                   64-, 128-bit Floating Point Package
  4.  
  5.                               June 2, 1985
  6.  
  7.                    Hakuou KATAYOSE (JUG-CP/M No.179)
  8.                     49-114 Kawauchi-Sanjuunin-machi, 
  9.                        Sendai, Miyagi 980, Japan
  10.                            Phone: 0222-61-3219
  11.   
  12. 1. Introduction
  13.      This floating point math package uses an omnibus routine written for
  14. the BDS C's CASM preprocessor.  In addition to arithmetic computations, 
  15. it provides trigonometric (sin, cos, atan), logarithmic, and exponential
  16. functions in 64-, 128-bit versions.   I think this has wide variety of 
  17. potential applications.
  18.  
  19.      The essential ideas of arithmetic computation implemented here have
  20. been borrowed from the following reference:
  21.     Y. Ookawa: "How to Write Arithmetic Programs for Microcomputers,"
  22.         Sanpou Publ., No.92 of Denshi-Kagaku (Electronics Science) Series.
  23.  
  24.      The package has the following syntax:
  25.  
  26.     fp64(func_No,a,b,c);
  27.  
  28. where func_No has been defined in the source program of FP-TEST.C.  
  29. The arguments  a, b, and c must be pointers to suitable strings defined 
  30. outside the fp64 function.  Examine FP-TEST.C for further explanation
  31. on the usage of fp64.
  32.  
  33. ----------------------------------------------------------------------
  34.   func_No   #define    Function
  35. ----------------------------------------------------------------------
  36.       0     FPGETK     Get constant defined in fp64
  37.       1     FPADD      c = a + b
  38.       2     FPSUB      c = a - b
  39.       3     FPMULT     c = a * b
  40.       4     FPDIV      c = a / b
  41.       5     FPCMP      C=1 ... a > b, C=0 ... a = b, c=-1 ... a < b    
  42.       6     FPNEG      c = -a
  43.       7     FPSFT      c = a X 2**b (-247 < b < 247)
  44.       8     FPHLF      c = a / 2
  45.       9     FPDBL      c = b X 2
  46.      10     FPCNV      Converts the floating number to ASCII for output
  47.      11     FPIN       Converts ASCII to floating number for input
  48.      12     FPSQRT     c = sqrt(a)
  49.      13     SINCOS     b = cos(a), c = sin(a); a is in radian.
  50.      14     ATAN2      c = tan(a/b)
  51.      15     EXP        c = 2**b
  52.      16     LOG        c = log b
  53. ----------------------------------------------------------------------
  54.  
  55.     The fundamental algorithm used by SINCOS and ATAN2 is CORDIC (COodinate 
  56. Rotation DIgital Computation); that for EXP and LOG is STL (Sequen-
  57. tial Table Lookup).  These algorithms were taken from:
  58.     S. Hitotsumatsu: "Numeric Computation of Elementary Functions,"
  59.         Modern Applied Mathematics Series, Kyoiku-Shuppan.
  60.  
  61.      CORDIC has been adopted for the trigonometric functions because:
  62.     1) Although it is rather slow (because it requires more steps
  63.            to make multiple-shift calculation), CORDIC results in
  64.            higher accuracy.  My priority was the accuracy.
  65.         2) The programming with bit shifts, addition and subtraction is
  66.            fairly straightforward.
  67.         3) When I read an article on CORDIC in the November 1976 
  68.            issue of INTERFACE magazine, I was fascinated the idea and
  69.            wanted to use it someday.
  70.  
  71.      The square root calculation consists of two steps: halving the
  72. exponent and then computing the square root of the mantissa with not
  73. more than  iterations of the NEwton-Raphson method.  The accuracy and 
  74. speed were much better than expected.
  75.  
  76.       I tried to apply CORDIC to the exp and log calculations, but 
  77. since it needed another table, I switched to STL since it requires only
  78. reduce the iteration by half.
  79.  
  80.      Another good reference on these subjects is:
  81.     J. Yamanouchi, T. Uno and S. Hitotsumatsu: "Numerical Methods 
  82.         for Digital Computers," Baifukan.
  83.  
  84. Additional notes:
  85.     1) Routines such as check and check22 at end of FP64 are for
  86.            debugging purposes, so maybe removed.
  87.         2) In parts, this package uses with Z80 code, so it won't work
  88.            for i8080 and i8085.
  89.         3) If you want to modify the package, you must process
  90.            FP64.CSM with CASM.COM and then assemble it with MAC.COM
  91.            and Z80.LIB.
  92.         4) Z80 relative jump instructions (e.g. DJNZ) appear as byte 
  93.            data, so you must change the relative offset by hand 
  94.            calculation.  This cannot be handled by CASM.COM.
  95.  
  96. Good luck and happy number crunching!
  97.